package listener;
import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;

//由MySttributeListener类实现application、session两类对象属性变化事件的监听

public class MyAttributeListener implements ServletContextAttributeListener,HttpSessionAttributeListener {

    public void attributeAdded(ServletContextAttributeEvent scae) {
        System.out.println("\n application对象中增加了一个名为" + scae.getName()
                + "的属性,该属性值为" + scae.getValue());
    }

    public void attributeRemoved(ServletContextAttributeEvent scae) {
        System.out.println("\n application对象中的" + scae.getName() + "属性被删除了\n");
    }

    public void attributeReplaced(ServletContextAttributeEvent scae) {
        System.out.println("\n application对象中" + scae.getName() + "的属性值被替换成了"
                + scae.getServletContext().getAttribute(scae.getName()));
    }


    public void attributeAdded(HttpSessionBindingEvent hbe) {
        System.out.println("\n session对象中增加了一个名为" + hbe.getName()
                + "的属性，该属性值为" + hbe.getValue());
    }

    public void attributeRemoved(HttpSessionBindingEvent hbe) {
        System.out.println("\n session对象中的" + hbe.getName() + "属性被删除了\n");
    }

    public void attributeReplaced(HttpSessionBindingEvent hbe) {
        System.out.println("\n session对象中" + hbe.getName() + "的属性值被替换成了"
                + hbe.getSession().getAttribute(hbe.getName()));
    }

}
